<?php
namespace app\frontend\controller;
use think\Db;
use think\Controller;
class Person extends Basic
{
    public function index()
    {
      if(!session('user_name'))
        {
            $user_name='登录';
            $user_register='注册';
            $user_logout='';
        }
        else
        {
        $user_name=session('user_name');
        $user_register='欢迎你';
        $user_logout='退出';
        }

        $this->assign('user_name',$user_name);
        $this->assign('user_register',$user_register);
        $this->assign('user_logout',$user_logout);

      $showtime_y=date("Y");
      $showtime_m=date("m");
      $showtime_d=date("d");
      
      $showtime_w=mb_substr( "日一二三四五六",date("w"),1,"utf-8" );
      $showtime=['y'=>$showtime_y,'m'=>$showtime_m,'d'=>$showtime_d,'w'=>$showtime_w];
      
      $this->assign('date',$showtime);
      
    	return view('./person/index');
    }
    public function men_level()
    {
       if(!session('user_name'))
        {
            $user_name='登录';
            $user_register='注册';
            $user_logout='';
        }
        else
        {
        $user_name=session('user_name');
        $user_register='欢迎你';
        $user_logout='退出';
        }

        $this->assign('user_name',$user_name);
        $this->assign('user_register',$user_register);
        $this->assign('user_logout',$user_logout);
        $user_id=session('user_id');
        $ret=db('user')->where("user_id={$user_id}")->select();
        foreach ($ret as $value) {
           $user_score=$value['user_score'];
           $user_birthday=$value['user_birthday'];
        }
           if($user_score>=50 and $user_score<100)
        {
          $user_level='Lv2';
        } 
        else if ($user_score>=100 and $user_score<150) {
          $user_level='Lv3';
        }
        else if ($user_score>=150) {
          $user_level='Lv3';
        }
        else
        {
          $user_level='Lv1';
        }
       
        $ret=db('user')->where("user_id={$user_id}")->update(['user_level'=>$user_level]);
        $this->assign('user_score',$user_score);
        $this->assign('user_birthday',$user_birthday);
        $this->assign('user_level',$user_level);
    	return view('./person/men_level');
    }
    public function level()
    {
    	return view('./person/level');
    }
    public function vip_card()
    {

       return view('./person/vip_card');
    }
 }